﻿Imports System.Data.SqlClient
Public Class FormHistory
    Private Sub FormHistory_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim cn As New SqlConnection
        cn.ConnectionString = "server=WINCTRL-B8GV7ME;uid=sa;pwd=123;database=AppSaleDb;"
        cn.Open()

        Dim cmd As New SqlCommand("SELECT * FROM tbl_SaleDetiles", cn)
        Dim dr = cmd.ExecuteReader()

        Dim dt As New DataTable()
        dt.Load(dr)
        dr.Close()

        Me.dgvHistorySale.DataSource = dt

        CalculateTotal()
        ' Payment()
    End Sub
    Public Sub CalculateTotal()
        Dim Amount As Decimal = 0.0
        For Each dgr As DataGridViewRow In dgvHistorySale.Rows
            Amount += dgr.Cells("Subtotal").Value
        Next
        txtmonetaty.Text = Amount
    End Sub
    'Public Sub Payment()
    '    Dim totalpay As Decimal = 0.0
    '    For Each dgr As DataGridViewRow In FormStock.DataGridViewStock.Rows
    '        totalpay += dgr.Cells("Total").Value
    '    Next
    '    txtPay.Text = totalpay
    'End Sub

    Private Sub btnSreach_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSreach.Click
        Dim cn As New SqlConnection
        cn.ConnectionString = "server=WINCTRL-B8GV7ME;uid=sa;pwd=123;database=AppSaleDb;"
        cn.Open()

        Dim cmd As New SqlCommand("SELECT * FROM tbl_SaleDetiles​where Date like '%" & dtpStart.Value.ToString("yyyy-MM-dd") & "%' and '%" & dtpEnd.Value.ToString("yyyy-MM-dd") & "%'", cn)
        Dim dr = cmd.ExecuteReader()

        Dim dt As New DataTable()
        dt.Load(dr)
        dr.Close()

        Me.dgvHistorySale.DataSource = dt
    End Sub

    Private Sub txtPay_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPay.TextChanged
        txtPay.Text = FormStock.LabelPriceIn.Text
    End Sub

    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click

    End Sub
End Class